package com.demo.commons;

/**
 * Created by Administrator on 2016/11/24.
 */

import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;

import java.net.InetAddress;

public class TimeRollingLogbackMachine<E> extends TimeBasedRollingPolicy<E> {
    public TimeRollingLogbackMachine() {
    }

    public void setFileNamePattern(String fnp) {
        if (fnp != null) {
            String hostName = this.getHostName();
            fnp = fnp.replace("#machineName", hostName);
        }

        super.setFileNamePattern(fnp);
    }

    private String getHostName() {
        String hostName = "";

        try {
            InetAddress e = InetAddress.getLocalHost();
            String ip = e.getHostAddress().toString();
            hostName = e.getHostName().toString();
        } catch (Exception var4) {
            hostName = "unKnowHostName";
        }

        return hostName;
    }
}